package nguyen.dao;

import java.sql.ResultSet;

import model.pojo.Employee;
import models.util.MD5;
import models.util.MySqlDataAccessHelper;

public class LoginSystem {

	public Employee checkLogin(String username,String pass,String databasename){
		MySqlDataAccessHelper mysql = new MySqlDataAccessHelper();
		mysql.open(databasename);
		Employee em = null;
		try {
			String sql="select * from employee where UserName='"+username+"' and Password='"+MD5.encrypt(pass)+"'";
			ResultSet rs = mysql.executeQuery(sql);
			if(rs==null)
				return em;
			while (rs.next()) {
				em = new Employee(rs.getString("IDEmployee"),
						rs.getString("UserName"), rs.getString("Password"),
						rs.getString("FullName"), rs.getString("Phone"),
						rs.getDate("Birthday"), rs.getString("Address"),
						rs.getString("Email"), rs.getString("Sex"),
						rs.getString("Position"), rs.getString("IDManager"),
						rs.getInt("IDDepartment"), rs.getInt("IDRole"),
						rs.getString("Description"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				mysql.close();
			}catch(Exception ex){
				ex.printStackTrace();
			}
		}
		return em;
	}	
}
